package com.yuneec.droneservice.command;

import com.MAVLink.yuneec.msg_mav_rc_cmd_ack;
import com.yuneec.droneservice.request.IResponse;

import java.nio.charset.Charset;

/**
 * Created by gjw on 2017/3/27.
 */

public class SendMd5 extends BaseCommand {
    private final byte[] md5;

    public SendMd5(String md5) {
        super(MAV_RC_COMMAND.MAV_RC_CMD_SEND_MD5);
        this.md5 = md5.getBytes(Charset.forName("utf8"));
    }

    @Override
    protected short[] body() {
        int totalLen = md5.length + 2;
        short[] body = new short[totalLen];
        shortToUIntArray(body, 0, (short) md5.length);
        byteArrayToUIntArray(body, 2, md5, 0);
        return body;
    }

    @Override
    public IResponse toResponse(msg_mav_rc_cmd_ack ack) {
        int code = ack.code;
        return new IResponse(ids(), code);
    }
}
